<?xml version="1.0"?>
<project name="EducationSystem" default="all">

	<tstamp property="build.date" pattern="dd-MM-yyyy" verbose="true"/>
	<sysinfo/>

    <property name="debug" value="true"/>

    <property name="project.target.dir" value="target"/>
    <property name="project.target.test.dir" value="target/test"/>
	<property name="project.target.docs.dir" value="target/docs"/>
    <property name="project.test.report.dir" value="reports"/>
    
    <property name="project.references.libs.dir" value="lib"/>
    <property name="project.data_access.name" value="DataAccess"/>
    <property name="project.data_access.src.dir" value="src/dotnet/DataAccess"/>
    
    <property name="project.resources.dir" value="src/resources"/>
    
    <property name="project.test.name" value="ESNunitTest"/>
    <property name="project.test.src.dir" value="src/test"/>
    
    <property name="nant.extension.nunit2report" value="target/test/NAnt.NUnit2ReportTasks.dll"/>
    
    <fileset basedir="${project.data_access.src.dir}" id="project.data_access.src">  
        <include name="**/*.cs"/>
    </fileset>
    
    <fileset basedir="${project.references.libs.dir}" id="project.references.libs">  
        <include name="**/*.dll"/>
    </fileset>

    <fileset basedir="${project.data_access.src.dir}" id="project.data_access.mappings">  
        <include name="**/*.hbm.xml"/>
        <include name="**/*.cfg.xml"/>
    </fileset>
    
    <fileset basedir="${project.test.src.dir}" id="project.test.src">  
        <include name="**/*.cs"/>
    </fileset>
    
    <fileset basedir="${project.resources.dir}" id="project.resources">  
        <include name="**/*.xml"/>
        <include name="**/*.xsl"/>
	<include name="**/*.config"/>
    </fileset>
    
    <target name="loadnanttask" description="Loads external the nant task" unless="${target::has-executed('loadnanttask')}">
        <loadtasks assembly="${nant.extension.nunit2report}" />
    </target>

    <target name="clean">
        <delete>
            <fileset>
                <include name="${project.target.dir}/*.*"/>
            </fileset>
        </delete>
    </target>

    <target name="build.data_access">
        <mkdir dir="${project.target.dir}" />
        <csc target="library" output="${project.target.dir}/${project.data_access.name}.dll" debug="${debug}">
            <sources refid="project.data_access.src"/>
            <references refid="project.references.libs"/>
        </csc>
    </target>
    
    <target name="copy.references">
        <copy todir="${project.target.dir}">
            <fileset refid="project.references.libs"/>
        </copy>
    </target>
    
    <target name="copy.mappings">
        <copy todir="${project.target.dir}">
            <fileset refid="project.data_access.mappings"/>
        </copy>
    </target>
    
    <target name="test.compile" depends="build.all">
        <mkdir dir="${project.target.test.dir}"/>
        <copy todir="${project.target.test.dir}">
            <fileset refid="project.references.libs"/>
        </copy>
        <copy todir="${project.target.test.dir}">
            <fileset basedir="${project.target.dir}">  
                <include name="*.dll"/>
            </fileset>
        </copy>
        <csc target="library" output="${project.target.test.dir}/${project.test.name}.dll">
            <sources refid="project.test.src"/>
            <references basedir="${project.target.test.dir}">
                <include name="**/*.dll"/>
                <exclude name="${project.target.test.dir}/${project.test.name}.dll"/>
            </references>
        </csc>
        <copy todir="${project.target.test.dir}">
            <fileset refid="project.resources"/>
        </copy>
    </target>
    
    <target name="test" depends="test.compile,loadnanttask">
        <mkdir dir="${project.test.report.dir}"/>
        <nunit2 failonerror="false">
            <formatter type="Xml" usefile="true" extension=".xml" outputdir="${project.test.report.dir}" />
            <!--formatter type="Plain"/-->
            <test assemblyname="${project.target.test.dir}/${project.test.name}.dll"/>
        </nunit2>
        <nunit2report format="frames" todir="reports">
            <fileset>
                <include name="${project.test.report.dir}/${project.test.name}.dll-results.xml" />
            </fileset>
        </nunit2report>
    </target>
	
	<target name="docs">
		<mkdir dir="${project.target.docs.dir}"/>
		<exec program="pdfLaTeX">
			<arg value="docs/dev/DevGuide.txt" />
			<arg value="-output-directory=${project.target.docs.dir}" />
		</exec>
	</target>
    
    <target name="build.all" depends="build.data_access">
    </target>

    <target name="all" depends="clean, build.all, copy.references, copy.mappings">
    </target>
</project>
